<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>axios使用</title>
		<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
		<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	</head>

	<body>
		<button id="btn1">get 不带参</button>===<span id="result1"></span>
		<hr />
		<button id="btn2">get 带参数</button>===<span id="result2"></span>
		<hr />
		<input type="file" name="file" id="file" value="" />
		<button id="btn3">post 上传文件</button>===<span id="result3"></span>
		
		<script type="text/javascript">
			document.getElementById("btn1").addEventListener('click',function(){
				axios.get('http://localhost:8084/ssm/toy/test')
					.then(function(response) {
						console.log(response);
						document.getElementById("result1").innerHTML = response.data;
					})
					.catch(function(error) {
						console.log(error);
						document.getElementById("result1").innerHTML = error;
					});
			})
			document.getElementById("btn2").addEventListener('click',function(){
				axios.get('http://localhost:8084/ssm/login', {
						params: {
							username: 'test',
							password:'123456'
						}
					})
					.then(function(response) {
						console.log(response);
						document.getElementById("result2").innerHTML = response.data;
					})
					.catch(function(error) {
						console.log(error);
						document.getElementById("result2").innerHTML = error;
					});
			})
			document.getElementById("btn3").addEventListener('click',function(){
				var file = document.getElementById("file").files[0];
				if(!file){
					return false;
				}
				var formData = new FormData();
				formData.append('file',file);
				formData.append('msg','axios post file')
				axios.post('http://localhost:8084/ssm/file/singleup', {
					  params: formData
					})
					.then(function(response) {
						console.log(response);
						document.getElementById("result3").innerHTML = response.data;
					})
					.catch(function(error) {
						console.log(error);
						document.getElementById("result2").innerHTML = error;
					});
			})
			
		</script>
	</body>

</html>